//新增
function addStaffInfo() {
    var data = {stat: 1};
    if (data) {
        showStaffInfoWindow(data, 0);
    }
}

function editStaffInfo() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: "/user/getuser/getLoginUserDepartId",
            type: "get",
            cache: false,
            async: false,
            success: function (success) {
                if (success.code == 1) {
                    var loginUserDepartId = success.data;
                    if (row.clab == loginUserDepartId) {
                        showStaffInfoWindow(row, 0);
                    } else {
                        showStaffInfoWindow(row, 1);
                    }
                } else {
                    return null;
                }
            }

        })
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

function showStaffInfoWindow(row, flog) {
    commonEdit("/azbj/gzzygl/staffInfoManage/edit/" + flog, "安帮工作人员信息", row, "55%", "68%", true, false, true, callback);

    function callback() {
        grid.reload();
    }
}

function delStaffInfo() {
    var row = grid.getSelected();
    if (row) {
        $.ajax({
            url: "/user/getuser/getLoginUserDepartId",
            type: "get",
            cache: false,
            async: false,
            success: function (success) {
                if (success.code == 1) {
                    var loginUserDepartId = success.data;
                    if (row.clab == loginUserDepartId) {
                        commonRemove("/azbj/gzzygl/staffInfoManage/delete/" + row.id, row, {_method: "delete"}, callback);

                        function callback() {
                            grid.reload();
                        }
                    } else {
                        mini.alert("非本机构添加的内容无法进行删除");
                    }
                } else {
                    return null;
                }
            }

        })
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

// 查看页面 - 安帮工作人员信息管理
function checkStaffInfo(){
    var row = grid.getSelected();
    if (row) {
        commonEdit("/azbj/gzzygl/staffInfoManage/edit/" + 1, "工作人员信息", row, "55%", "55%", true, true, true, callback);
        function callback() {
            grid.reload();
        }
    } else {
        mini.alert("请至少选择一条数据！");
    }
}

//格式化日期函数
function onDateRenderer(e) {
    var date = new Date(e.value);
    var Y = date.getFullYear() + '-';
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1) + '-';
    var D = (date.getDate() < 10 ? '0' + date.getDate() : date.getDate()) + ' ';
    var h = (date.getHours() < 10 ? '0' + date.getHours() : date.getHours()) + ':';
    var m = (date.getMinutes() < 10 ? '0' + date.getMinutes() : date.getMinutes()) + ':';
    var s = (date.getSeconds() < 10 ? '0' + date.getSeconds() : date.getSeconds());
    var formatTime = Y + M + D + h + m + s;
    return formatTime;
}

//工作人员类别转化
function onChangeCode(e) {
    var gzrytype = e.value;
    if (gzrytype == 1) {
        return "司法机构安置帮教工作人员";
    } else if (gzrytype == 2) {
        return "从事安置帮教工作的社会工作者";
    } else if (gzrytype == 3) {
        return "稳控民警";
    } else {
        return "其他";
    }
}

//帮扶范围转化
function onHelpAreaStatus(e) {
    var helpAreaType = e.value;
    if (helpAreaType == 1) {
        return "本省";
    } else if (helpAreaType == 2) {
        return "本市";
    } else if (helpAreaType == 3) {
        return "本区县";
    } else {
        return "本乡镇";
    }
}

//性别code转换
function onGetGenderName(e) {
    var gender = e.value;
    if(gender==1){
        return "男性";
    } else if(gender==2){
        return "女性";
    } else if(gender==0){
        return "未知的性别";
    } else if(gender==9){
        return "未说明的性别";
    }
}

//是否参与帮扶工作code转换
function onGetWorkStatus(e) {
    var workStatus = e.value;
    if (workStatus == 1) {
        return "是";
    } else if (workStatus == 2) {
        return "否";
    } else {
        return "其他";
    }
}

//批量导出
function exportExcelFile(e) {
    var num = grid.getData().length;
    if (num > 0) {
        top.location.href = encodeURI("/azbj/abwordresource/common/exportExcelFile?type=1");
    } else {
        mini.alert("没有数据可导出");
    }
}